home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97b.txt / 000135_icon-group-sender _Wed Dec 10 08:15:31 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by baskerville.CS.Arizona.EDU (8.8.7/8.8.7) with SMTP id IAA02934
  4.     for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Wed, 10 Dec 1997 08:15:31 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA09574; Wed, 10 Dec 1997 08:15:30 -0700
  7. Date: Tue, 9 Dec 1997 12:50:11 -0800
  8. From: kwalker@premenos.com (Ken Walker)
  9. Message-Id: <199712092050.MAA02602@varda.premenos.com>
  10. To: icon-group@baskerville.CS.Arizona.EDU, turk@ionet.net
  11. Subject: Re: do while
  12. Mime-Version: 1.0
  13. Content-Type: text/plain; charset=us-ascii
  14. Content-Transfer-Encoding: 7bit
  15. Content-Md5: UicDfU8TKuatexnNBIVvtw==
  16. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  17. Status: RO
  18.  
  19. > Date: Tue, 09 Dec 1997 11:34:40 -0600
  20. > From: "Dr. Louis A. Turk" <turk@ionet.net>
  21. >
  22. > ...
  23. > How do you write a do while control statement in Icon?   I need something
  24. > kind of like this:
  25. > do {
  26. >    ...
  27. > } while line := read(file)
  28. > I have tried to use repeat, but cannot seem to figure out how to cause a
  29. > break at the end of file.  This one is, I am sure, very simple, but it
  30. > eludes me.
  31.  
  32. read() fails when it reaches end-of-file. You can provide a break expression
  33. as an alternative and the loop will terminate when read() fails:
  34.  
  35.    procedure main()
  36.     local line, file
  37.  
  38.     file := open("temp") | stop("cannot open file")
  39.  
  40.     repeat {
  41.         line := read(file) | break
  42.         write(line)
  43.     }
  44.  
  45.     write("**done**")
  46.    end
  47.  
  48. If you need to break out of multiple nested loops you can use another
  49. break as an argument to the first one.
  50.  
  51.  
  52. Ken Walker, kwalker@premenos.com
  53. Premenos Coporation, Concord, Ca. 94520
  54.  
  55.